﻿using System;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GmailChecker.Utils
{
    static class MailBoxTimer
    {
        public static void AddEvent(Timer timer)
        {
            timer.Tick += Tick;
        }

        public static void Init(Timer timer)
        {
            if (string.IsNullOrEmpty(MailBox.Email) || string.IsNullOrEmpty(MailBox.Password) || MailBox.Email.Length < 6 || MailBox.Password.Length < 6)
            {
                timer.Enabled = false;
            }
            else
            {
                timer.Interval = 5000;
                timer.Enabled = true;
            }
        }

        private static void Tick(object sender, EventArgs e)
        {           
            if (!App.WaitDialogResult)
            {
                Task.Factory.StartNew(MailBox.Check);         
            }            
        }
    }
}
